package internal_test

import (
	"testing"

	"gitcode.com/lin-xii/algorithm-and-structure/internal"
)

func TestLinearSearch(t *testing.T) {
	list := []int{10, 20, 30, 40, 50}

	// 能找到
	index := internal.LinearSearch(list, 20)
	if index == nil {
		t.Errorf("expect index not nil, got %+v", index)
	}
	if index != nil && *index != 1 {
		t.Errorf("expect index 1, got %+v", *index)
	}

	// 找不到
	index = internal.LinearSearch(list, 0)
	if index != nil {
		t.Errorf("expect index nil, got %+v", index)
	}

	// 空list
	index = internal.LinearSearch([]int{}, 2233)
	if index != nil {
		t.Errorf("expect index nil, got %+v", index)
	}

}
